package com.qf.controller;



import com.qf.pojo.Parent;
import com.qf.service.ParentService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/parent")
public class ParentController {
    @Autowired
    ParentService parentService;

    @GetMapping("/selectAllParent")
    public ResultMsg selectAllParent(@RequestParam(required = false, defaultValue = "") String name, @RequestParam(required = false, defaultValue = "-1") Integer parentId, @RequestParam(required = false, defaultValue = "-1") Integer parentStatus, @RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "10") Integer limit) {
        return parentService.selectAllParent(name,parentId,parentStatus,page,limit);
    }
    @GetMapping("/selectOneParent")
    public ResultMsg selectOneParent(@RequestParam(required = false) Integer parentId) {
        ResultMsg resultMsg = parentService.selectOneParent(parentId);
        return resultMsg;
    }

    @PutMapping("/updateParent")
    public ResultMsg updateParent(@RequestBody Parent parent) {
        return parentService.updateParent(parent);
    }

    @PutMapping("/insertParent")
    public ResultMsg insertParent(@RequestBody Parent parent) {
        return parentService.insertParent(parent);
    }

    @PutMapping("/updateParentStatus")
    public ResultMsg updateParentStatus(@RequestBody Map<String, Object> map) {
        return parentService.updateParentStatus((List<Integer>) map.get("parentIds"), (Integer) map.get("parentStatus"));
    }

    @DeleteMapping("/deleteparent")
    public ResultMsg deleteParent(@RequestBody Map<String, List<Integer>> map){
        return parentService.deleteParent(map.get("parentIds"));
    }

}
